import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class MyThreadPoll {

    BlockingQueue<Runnable> blockingQueue = new LinkedBlockingQueue<>();

    public void submit(Runnable runnable) {
        try {
            blockingQueue.put(runnable);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public MyThreadPoll(int n ) {
        for (int i = 0; i < n; i++) {
            Thread t = new Thread(() -> {
                while(Thread.currentThread().isInterrupted()) {
                    try {
                        Runnable runnable = blockingQueue.take();
                        runnable.run();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        break;
                    }
                }
            });
            t.start();
        }
    }

}


public class Demo {
    public static void main(String[] args) {
        MyThreadPoll myThreadPoll = new MyThreadPoll(10);
        for (int i = 0; i < 10; i++) {
            myThreadPoll.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("World");
                }
            });
        }
    }
}
